<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>首页</title>
    <link rel="stylesheet" type="text/css" href="../../aui/css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../aui/css/aui-iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/css.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/swiper-3.3.1.min.css"/>
</head>

<body>
<style>
    .reg-body {
        background: #f0f0f0;
        width: 100%;
        height: 100%;
        position: fixed;
    }

    [v-cloak] {
        display: none;
    }

    .reg-1 {
        width: 100%;
        background: #fff;
        height: 200px;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        flex-direction: column;
    }

    .reg-tel {
        width: 92%;
        border-bottom: 1px solid #f8f8f8;
        height: 60px;
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }

    .reg-tel .reg-tel_label {
        width: 100px;
        font-size: 16px;
        color: #666666;
    }

    .reg-button {
        width: 80%;
        height: 45px;
        background: rgba(109, 67, 229, 1);
        border-radius: 5px;
        margin: 40px auto;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-size: 16px;
    }

    .container {
        /*position: absolute;*/
        bottom: 30px;
        padding: 10px;
        text-align: center;
        padding-top: 30px;
    }

    .container p {
        font-family: "微软雅黑";
        color: #888;
    }

    .val-box {
        display: inline-block;
        height: 40px;
        width: 216px;
        text-align: center;
        position: relative;
        background: #FFFFFF;
        -webkit-tap-highlight-color: transparent;
    }

    .val-box input[type=text] {
        position: absolute;
        left: 0;
        top: 0;
        height: 37px;
        width: 212px;
        opacity: 0.9;
        z-index: -999;
        outline: none;
        margin-left: 1000px;
        -webkit-tap-highlight-color: transparent;
    }

    .val-box div {
        height: 38px;
        width: 22%;
        border: 1px solid #DDD;
        border-radius: 5px;
        float: left;
        margin: 2px 3px;
        z-index: 5;
        font-size: 1.5em;
        font-family: arial;
        /*font-weight: 530;*/
        text-align: center;
        line-height: 1.5em;
        cursor: text;
        /*padding-bottom: 10px;*/
    }

    .val-box .available {
        border-color: #0081db;
    }

    .reg-code {
        background: #fff;
        padding-bottom: 10px;
    }

    .reg-code .reg-button {
        padding: 20px;
    }

    .xieyi {
        background: #ededed;
        position: fixed;
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        flex-direction: column;
    }

    .xieyidesc {
        width: 90%;
        margin: auto;
        height: 450px;
        margin-top: 30px;
        background: rgba(255, 255, 255, 1);
        box-shadow: 0px 10px 40px 0px rgba(153, 153, 153, 0.2);
        border-radius: 5px;
    }

    .xieyidesc .xieyidesctitle {
        padding-top: 20px;
        margin-bottom: 20px;
        font-size: 16px;
        font-family: MicrosoftYaHei;
        font-weight: bold;
        color: rgba(51, 51, 51, 1);
        text-align: center;
    }

    .xieyidesc .xieyidesccont {
        overflow: scroll;
        height: 350px;
        width: 90%;
        margin: auto;
    }

    .xieyititle {
        margin-top: 20px;
        position: fixed;
        bottom: 20px;
        left: 0;
        font-size: 12px;
        width: 100%;
        text-align: center;
        color: #999999;
    }

    .xieyititle span {
        color: #6D43E5;
    }
    .inputStyle{
        height: 38px !important;
        width: 50px !important;
        border: 1px solid #DDD !important;
        border-radius: 5px;
        float: left;
        margin: 2px 3px;
        z-index: 5;
        font-size:14px !important;
        font-family: arial;
        /* font-weight: 530; */
        text-align: center;
        line-height: 38px !important;
        cursor: text;
        /* padding-bottom: 10px; */
        margin-left: 10px;
        margin-right: 10px;
    }
    .code{
        width: 80%;
        display: flex;
        justify-content: space-around;
        align-items: center;
        margin: auto;
        margin-top: 20px;
        padding-top: 30px;
    }

</style>
<div id="app">
    <div id="wraps" class="flex-wrap bgn flex-vertical">
        <header>
            <ul>
                <li class="active">
                    <!--<i onclick="back()" class="icon iconfont icon-back"></i>-->
                    <span>{{title}}</span>
                </li>
            </ul>
        </header>
        <div class="reg-body">
            <div v-if="status==0" class="reg-1 fixed-header">
                <div class="reg-tel">
                    <div class="reg-tel_label">
                        +86
                    </div>
                    <div class="reg-tel_input">
                        <input v-model="tel" type="number" placeholder="请输入电话">
                    </div>
                </div>
                <div class="reg-button" @click="getCode">
                    下一步
                </div>
            </div>
            <div v-if="status==1" class="reg-code fixed-header">
                <div id="shoujihao">
                    <span></span>
                    <div class="code">
                        <input id="first" class="inputStyle" v-model="code[0]" type="number"/>
                        <input id="second" class="inputStyle" v-model="code[1]"style="border-left:1px solid #c6c6c6;" type="number"/>
                        <input id="third" class="inputStyle" v-model="code[2]"style="border-left:1px solid #c6c6c6;" type="number"/>
                        <input id="forth" class="inputStyle" v-model="code[3]" style="border-left:1px solid #c6c6c6;" type="number"/>
                    </div>
                    <div class="reg-button" @click="getLogin">
                        完善资料
                    </div>
                </div>
            </div>
            <div v-if="status==2" class="xieyi fixed-header">
                <div class="xieyidesc">
                    <div class="xieyidesctitle">用户规则</div>
                    <div class="xieyidesccont">
                        最近的用户请必须遵守以下协议最近的用户请必 须遵守以下协议最近的用户请必须遵守以下协议 最近的用户请必须遵守以下协议最近的用户
                        最近的用户请必须遵守以下协议最近的用户请必 须遵守以下协议最近的用户请必须遵守以下协议 最近的用户请必须遵守以下协议最近的用户
                        最近的用户请必须遵守以下协议最近的用户请必 须遵守以下协议最近的用户请必须遵守以下协议 最近的用户请必须遵守以下协议最近的用户
                        最近的用户请必须遵守以下协议最近的用户请必 须遵守以下协议最近的用户请必须遵守以下协议 最近的用户请必须遵守以下协议最近的用户
                        最近的用户请必须遵守以下协议最近的用户请必 须遵守以下协议最近的用户请必须遵守以下协议 最近的用户请必须遵守以下协议最近的用户
                        最近的用户请必须遵守以下协议最近的用户请必 须遵守以下协议最近的用户请必须遵守以下协议 最近的用户请必须遵守以下协议最近的用户
                        最近的用户请必须遵守以下协议最近的用户请必 须遵守以下协议最近的用户请必须遵守以下协议 最近的用户请必须遵守以下协议最近的用户
                        最近的用户请必须遵守以下协议最近的用户请必 须遵守以下协议最近的用户请必须遵守以下协议 最近的用户请必须遵守以下协议最近的用户
                    </div>
                </div>
                <div class="xieyititle">注册即表示同意《<span>陪聊交友用户协议</span>》和《<span>隐私权政策</span>》
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="../../aui/js/aui.js"></script>
<script src="../../script/vue2.js"></script>
<script src="../../script/vue-resource.min.js"></script>
<script src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/swiper-3.3.1.min.js"></script>
<script type="text/javascript">
    apiready = function () {
    var main = new Vue({
        el: "#app",
        data: {
            title: '注册',
            tel: '',
            status: 0,
            code: '',
            smsCode: '',
            code: new Array(5),
            codeId: ['first', 'second', 'third', 'forth']

        },
        mounted: function () {
            var that = this;
        },
        methods: {
            getCode: function () {
                var that = this;
                if (that.tel == '') {
                    api.toast({msg: '请输入手机号', location: 'middle'});
                    return
                }
                if (that.tel.length < 11) {
                    api.toast({msg: '请输入正确的手机号', location: 'middle'});
                    return
                }
                showProgress();

                api.ajax({
                    url: ajaxRoute.sms,
                    method: 'post',
                    data: {
                        values: {
                            mobile: this.tel,
                            event: 'register',
                        }
                    }
                }, function (ret, err) {
                    if (ret.code == 1) {
                        api.toast({msg: '验证码发送成功', location: 'middle'});
                        that.status = 1
                    } else {
                        api.hideProgress();
                        api.toast({msg: ret.msg, location: 'middle'});
                    }
                });
            },
            getLogin: function () {
                var that = this;
                if (that.code == '') {
                    api.toast({msg: '请输入验证码', location: 'middle'});
                    return
                }
                if (that.code.length < 4) {
                    api.toast({msg: '请输入正确验证码', location: 'middle'});
                    return
                }
                showProgress();
                console.log(this.code);
                api.ajax({
                    url: ajaxRoute.mobilelogin,
                    method: 'post',
                    data: {
                        values: {
                            mobile: this.tel,
                            captcha: this.smsCode,
                        }
                    }
                }, function (ret, err) {
                    if (ret.code == 1) {
                        $api.setStorage('userInfo', ret.data.userinfo)
                        api.openFrame({
                            name: 'regs',
                            url: 'widget://html/reg/perfect.html',
                            rect: {
                                x: 0,
                                y: 0,
                                w: 'auto',
                                h: 'auto'
                            },
                            pageParam: {
                                id: ret.data.stage
                            }
                        });
                    } else {
                        api.hideProgress();
                        api.toast({msg: ret.msg, location: 'middle'});
                    }
                });
            },
        },
        filters: {},
        watch: {
            code: function(newValue, oldValue) {
                console.log('newValue.length' + newValue.length)
                let tempValue = ''
                for (let i = 0; i < newValue.length; i++) {
                    if (i == 5) {
                        console.log(i)
                        break
                    }
                    if (newValue[i]) {
                        tempValue = tempValue + newValue[i]
                    }
                }
                this.smsCode = tempValue
                console.log('smsCode ' + this.smsCode)
                let m = tempValue.split("")
                let location = 0
                for (let i = 0; i < newValue.length; i++) {
                    if (m[i] && i < 4) {
                        location++
                        newValue[i] = m[i]
                    } else {
                        newValue[i] = ''
                    }
                }
                // console.log(this.codeId[i])
                if (location < 1) {
                    location = 1
                } else if (location > 5) {
                    location = 5
                }
                document.getElementById(this.codeId[location - 1]).focus()
            }
        },
    })
    }
</script>

</html>
